/**
 * 
 * Sun CMS
 * 
 * @author			Burning
 * @copyright		Copyright (c) 2009, SunWeber.Com.
 * @license			http://www.sunweber.com/license.htm
 * @link				http://www.sunweber.com/
 * @since				Version 1.0 Beta
 * 
 */

function view_thumb_pic(str)
{
	if( str == 'show' )
	{
		var thumb_pic = $("#thumb_pic").val();
		if( thumb_pic == '' ) return false;
		if( thumb_pic.match(/\.(jpg|jpeg|gif|bmp|png)$/i) ) $("#view_thumb").attr('src','uploads/thumb/'+thumb_pic).show();
		else $("#thumb_pic").val('');
	}
	else $("#view_thumb").hide();
}

function get_special()
{
	var special = special_name = '';
	$("#get_special .checkbox").each(function(){
		if( $(this).attr('checked') == true )
		{
			var sid = $(this).val();
			special += sid+' ';
			special_name += $("#get_special #sid_"+sid).val()+' ';
		}
	});
	$("#special").val(special);
	$("#special_name").val(special_name);
	sctab(2);
}

function get_city( n)
{
	var n = $("#province").val();
	if( n == 0 ) $("#city").html("<option value='0'></option>");
	else
	{
		$.ajax({
			type: "POST",
			url: script+"?m=article&a=getcity",
			data: {'pid':n},
			dataType:'json',
			success: function(rs){
				if(rs)
				{
					$("#city").html('');
					var no = rs.length;
					if( no == 0 ) $("#city").append("<option value='0'></option>");
					else
					{
						var html;
						for(i=0; i<no; i++){
							$("#city").append("<option value="+rs[i].id+">&nbsp;&nbsp;&nbsp;"+rs[i].name+"</option>");
						}
					}
				}
				else return false;
			}
		});
	}
}

var old_selected = 0;
function tr_selected(n)
{
	$("#tr_"+old_selected).removeClass("tr_selected");
	$("#tr_"+old_selected+" .checkbox").removeAttr("checked");
	$("#tr_"+n).addClass('tr_selected');
	$("#tr_"+n+" .checkbox").attr("checked", 'true');
	old_selected = n;
}




function insert_aft(str){
	$("#"+str[0]).attr("value",str[1]);
	$("#"+str[0]+'list').hide();
}

function select_co(){
	$("#color").show();
}

function color_select(str){
	$("#title_color").attr("value",str);
	sclose('color');
}



function update_author(){
	var value = $("#author").val();
	$.ajax({
		type: "POST",
		url: base_url+"?m=arhelper&a=saveauthor",
		data: {'author':value},
		dataType:'json',
		success: function(rs){
			if(rs.ok==1){
				$("#saveauthor").text("作者列表已保存！");
			}else{
				$("#saveauthor").text(rs.error);
			}
			$("#saveauthor").fadeIn();
			setTimeout(
				"$('#saveauthor').fadeOut(1000)",2000
			);
		}
	});
}

function update_from(){
	var value = $("#from").val();
	$.ajax({
		type: "POST",
		url: base_url+"?m=arhelper&a=savefrom",
		data: {'author':value},
		dataType:'json',
		success: function(rs){
			if(rs.ok==1){
				$("#savefrom").text("来源列表已保存！");
			}else{
				$("#savefrom").text(rs.error);
			}
			$("#savefrom").fadeIn();
			setTimeout(
				"$('#savefrom').fadeOut(1000)",2000
			);
		}
	});
}

function ar_validate(str){
	var ar = get_selected();
	if(ar=='')
	{
		alert('错误的操作，未选择任何运行参数！');
		return false;
	}
	var arString = ar.join('_');
	$.ajax({
		type: "POST",
		url: base_url+"?m=article&a=validate&tp="+str,
		data: {'ids':arString},
		dataType:'json',
		success: function(rs){
			if(rs.ok){
				for(x in ar){
					if(str=='validate'){
						$("#ar_"+ar[x]+" img").replaceWith("<img height='16' width='16' border='0' alt='是' src='images/admin/tick.png'/>")
					}else{
						$("#ar_"+ar[x]+" img").replaceWith("<img height='16' width='16' border='0' alt='否' src='images/admin/publish_x.png'/>")
					}
				}
			}
		}
	});
}

function ar_do(str){
	var ar = get_selected();
	if(ar==''){
		alert('错误的操作，未选择任何运行参数！');
		return false;
	}
	if(str=='delete'){
		if(confirm('此操作不可恢复,是否确定删除？')==false){
			return false;
		}
	}
	var arString = ar.join('_');
	window.location=base_url+'?m=article&a='+str+'&ids='+arString;
}

function ar_list_page(str){
	$("#sys_msg").text('数据加载中。。。').fadeIn();
	var url = str[0];
	var page = str[1];
	$.ajax({
		type: "POST",
		url: url,
		data: {'pg':page},
		dataType:'json',
		success: function(rs){
			$("#sys_msg").fadeOut();
			$(".mytable tr:gt(0)").remove();
			$(".mytable tr").after(rs.articles);
			$("#page_link").replaceWith(rs.page_link);
			onload_page();
		}
	});
}

function column_ar_list(){
	var cid = $("#ar_column").val();
	if(cid==0){
		return false;
	}else{
		window.location=base_url+'?m=article&a=index&type=cg&id='+cid;
	}
}

function search_article(){
	var rule = $("#search_rule").val();
	var key = $("#search_key").val();
	if(rule==0){
		alert('请选择筛选规则！');
		return false;
	}
	if(key==''){
		alert('筛选值不能为空！');
		return false;
	}
	window.location=base_url+'?m=article&a=search&rule='+rule+'&key='+key;
}

var move_articles = '';
function article_move_page(str){
	if(str==0){
		$("#article_move").hide();
		return true;
	}else{
		var ar = get_selected();
		if(ar==''){
			alert('错误的操作，未选择任何运行参数！');
			return false;
		}
		move_articles = ar.join('_');
		$("#article_move").show();
	}
}

function article_move(){
	var column = $("#move_column").val();
	if(column==0){
		alert('请选择要文章要移动到的栏目！');
		return false;
	}
	$("#article_move").hide();
	window.location=base_url+'?m=article&a=move&ids='+move_articles+'&cid='+column;
}